class Solution {
public:
    ListNode* oddEvenList(ListNode* head) {
        ListNode* j = new ListNode(0);
        ListNode* jHead = j;
        ListNode* o = new ListNode(0);
        ListNode* oHead = o;
        int i=1;
        while(head!=nullptr){
          if(i%2==1){
            j->next=head;
            j=j->next;
          }else{
            o->next=head;
            o=o->next;
          }
          head=head->next;
          i++;
        }
        o->next=nullptr;
        j->next=oHead->next;
        return jHead->next;
    }
};
